<ui:composition template="/WEB-INF/templates/layout.xhtml"
                xmlns="http://www.w3.org/1999/xhtml"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:p="http://primefaces.org/ui">
    <ui:define name="content">
        <p:dialog header="#{i18n['label.user.title']}" modal="true" appendTo="@(body)"
                  visible="true" resizable="true" closable="true" widgetVar="dlg_cad_user" 
                  position="center" width="500"
                  >
            <h:form id="form_edit">
                <h:panelGrid columns="3" >
                    <p:outputLabel value="#{i18n['label.user.name']}"/>
                    <p:inputText value="#{userMB.user.name}" size="40" required="true" requiredMessage="#{i18n['label.user.name.required']}"/>
                    <p:commandButton icon="ui-icon-search"
                                     ajax="true"
                                     immediate="true"
                                     actionListener="#{userMB.loadUsers}"
                                     oncomplete="dlg_list_users.show()"
                                     update=":form_show"/>

                    <p:outputLabel value="Privilégios"/>
                    <h:panelGrid columns="2" >
                        <p:selectBooleanCheckbox value="#{userMB.user.administrator}"/>
                        <p:outputLabel value="#{i18n['label.user.is_administrator']}"/>

                        <p:selectBooleanCheckbox value="#{userMB.user.project_controller}"/>
                        <p:outputLabel value="#{i18n['label.user.is_prj_controller']}"/>

                        <p:selectBooleanCheckbox value="#{userMB.user.project_viewer}"/>
                        <p:outputLabel value="#{i18n['label.user.is_prj_viewer']}"/>

                    </h:panelGrid>
                    <p:outputLabel value=""/>

                    <p:outputLabel value="#{i18n['label.user.email']}"/>
                    <p:inputText value="#{userMB.user.email}" size="40" required="true" requiredMessage="#{i18n['label.user.email.required']}"/>
                    <p:outputLabel/>

                    <p:outputLabel value="#{i18n['label.user.password']}"/>
                    <p:password id="pw1" value="#{userMB.user.password}" match="pw2" required="true" requiredMessage="#{i18n['label.user.password.required']}" validatorMessage="#{i18n['label.user.password.validation']}"/>
                    <p:outputLabel/>

                    <p:outputLabel value="#{i18n['label.user.confirm_password']}" />
                    <p:password id="pw2" required="true" requiredMessage="#{i18n['label.user.confirm_password.required']}"/>
                    <p:outputLabel/>
                </h:panelGrid>
                <h:panelGrid columns="3">
                    <p:commandButton value="#{userMB.user.id == 0? i18n['label.save'] : i18n['label.update']}"
                                     actionListener="#{userMB.cadNewUser}"
                                     ajax="false"
                                     process="@form"
                                     update="@form"
                                     icon="#{userMB.user.id ==0 ? 'ui-icon-disk': 'ui-icon-refresh'}"/>

                    <p:commandButton value="#{i18n['label.clear']}" ajax="true" immediate="true" actionListener="#{userMB.clear}" update="@all"
                                     icon="ui-icon-cancel"/>

                    <p:commandButton value="#{i18n['label.delete']}" ajax="true" 
                                     actionListener="#{userMB.remove}" update="@form"
                                     rendered="#{userMB.user.id != 0}"
                                     icon="ui-icon-trash">
                        <p:confirm header="#{i18n['label.confirmation']}" message="#{i18n['label.message.description']}" icon="ui-icon-alert"/>
                    </p:commandButton>
                </h:panelGrid>

            </h:form>
        </p:dialog>      
        <p:dialog header="#{i18n['label.user.list']}" width="40%" visible="false" 
                  widgetVar="dlg_list_users" modal="true" appendTo="@(body)"
                  resizable="false"  position="center">
            <h:form id="form_show">
                <p:dataTable var="user" value="#{userMB.users}" scrollable="true" id="dt_user"
                             selection="#{userMB.user}" selectionMode="single" rowKey="#{user.id}">
                    <p:column headerText="#{i18n['label.user.email']}">  
                        <h:outputText value="#{user.email}" />  
                    </p:column>  

                    <p:column headerText="#{i18n['label.user.password']}">  
                        <h:outputText value="#{user.password}" />  
                    </p:column>  
                    <f:facet name="footer">  
                        <p:commandButton  value="#{i18n['label.view']}" icon="ui-icon-search" oncomplete="dlg_list_users.hide();" update=":form_edit"/>  
                    </f:facet> 
                </p:dataTable>
            </h:form> 
        </p:dialog>
    </ui:define>
</ui:composition>